define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {

        index: function () {
            Controller.api.bindevent();
            // 初始化表格参数配置
            Table.api.init();
            //绑定事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var panel = $($(this).attr("href"));
                if (panel.length > 0) {
                    Controller.table[panel.attr("id")].call(this);
                    $(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });
                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            });

            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
            Controller.api.bindevent();

        },

        table: {
            starting_price: function () {
                // 会议日程
                var table_starting_price = $("#table_starting_price");
                table_starting_price.bootstrapTable({
                    url: 'wddj/operationt/starting_price/index?city_id=' + Config.city_id,
                    extend: {
                        index_url: 'wddj/operationt/starting_price/index' + location.search,
                        add_url: 'wddj/operationt/starting_price/add?city_id='+ Config.city_id,
                        edit_url: 'wddj/operationt/starting_price/edit',
                        del_url: 'wddj/operationt/starting_price/del',
                        table: 'wddj_starting_price',
                    },
                    toolbar: '#toolbar_starting_price',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id')},
                            {field: 'start_time', title: __('Start_time')},
                            {field: 'end_time', title: __('End_time')},
                            {field: 'price', title: __('Price'), operate:'BETWEEN'},
                            {field: 'vehicle.name', title: __('Vehicle_type'), operate:'LIKE'},
                            // {field: 'area_names', title: __('Area_names'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                            // {field: 'area_names', title: __('Area_names'), operate: false, formatter:function (value , row ,index) {
                            //         let element = '';
                            //         let data = value.split(',');
                            //         for (let i = 0; i < data.length; i++) {
                            //             element += data[i]+'<br/>';
                            //         }
                            //
                            //         return element;
                            //
                            //     }, operate:'LIKE'},
                            {field: 'area_names', title: __('Area_names'),formatter : function(value, row, index, field){
                                    return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space:nowrap;' title='" + row.area_names.replace(/,/g,'&#10;') + "'>" + value + "</span>";
                                },
                                cellStyle : function(value, row, index, field) {
                                    return {
                                        css: {
                                            "white-space": "nowrap",
                                            "text-overflow": "ellipsis",
                                            "overflow": "hidden",
                                            "max-width": "250px"
                                        }
                                    };
                                }, operate: 'LIKE'},
                            // {field: 'kilometer', title: __('Kilometer'), operate:'BETWEEN'},
                            // {field: 'weigh', title: __('Weigh'), operate: false},
                            {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                            {field: 'operate', title: __('Operate'), table: table_starting_price, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });

                // 为会议日程绑定事件
                Table.api.bindevent(table_starting_price);
            },



        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
